import { createRouter, createWebHashHistory } from "vue-router";

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    component: () => import("../views/Home.vue"),
    children: [
      {
        path: "/home",
        redirect: "/home/index",
      },
      {
        path: "/home/index",
        component: () => import("../views/home/Index.vue"),
      },
      {
        path: "/home/chat",
        component: () => import("../views/home/Chat.vue"),
      },
      {
        path: "/home/cus",
        component: () => import("../views/home/Customization.vue"),
      },
      {
        path: "/home/mine",
        component: () => import("../views/home/Mine.vue"),
      },
    ],
  },
  {
    path: "/fastlogin",
    component: () => import("../views/register&login/FastLogin.vue"),
  },
  {
    path: "/login",
    component: () => import("../views/register&login/Login.vue"),
  },
  {
    path: "/register",
    component: () => import("../views/register&login/Register.vue"),
  },
  {
    path: "/detail/:_id",
    component: () => import("../views/Detail.vue"),
    props: true,
  },
  {
    path: "/tryimage",
    component: () => import("../views/TryImage.vue"),
  },
  {
    path: "/brand",
    component: () => import("../views/Brand.vue"),
    children: [
      {
        path: "/brand",
        redirect: "/brand/hot",
      },
      {
        path: "/brand/hot",
        component: () => import("../views/brand/hot.vue"),
      },
      {
        path: "/brand/score",
        component: () => import("../views/brand/score.vue"),
      },
      {
        path: "/brand/repurchase",
        component: () => import("../views/brand/repurchase.vue"),
      },
    ],
  },
  {
    path: "/list",
    component: () => import("../views/List.vue"),
    children: [
      {
        path: "/list",
        redirect: "/list/up"
      },
      {
        path: "/list/up",
        component: () => import("../components/List/Up.vue"),
      },
      {
        path: "/list/foundation",
        component: () => import("../components/List/Foundation.vue"),
      },
      {
        path: "/list/makeup",
        component: () => import("../components/List/Makeup.vue"),
      },
      {
        path: "/list/skincare",
        component: () => import("../components/List/Skincare.vue"),
      },
    ],
  },
  {
    path: "/mplist",
    component: () => import("../views/mpList.vue"),
    children: [
      {
        path: "/mplist",
        redirect: "/mplist/upd"
      },
      {
        path: "/mplist/upd",
        component: () => import("../components/List/Upd.vue"),
      },
      {
        path: "/mplist/foundation",
        component: () => import("../components/List/Foundation.vue"),
      },
      {
        path: "/mplist/makeup",
        component: () => import("../components/List/Makeup.vue"),
      },
      {
        path: "/mplist/skincare",
        component: () => import("../components/List/Skincare.vue"),
      },
    ],
  },
  {
    path: "/skinchange",
    component: () => import("../views/SkinChange.vue"),
  },
  {
    path: "/searchb",
    component: () => import("../views/Search/searchb.vue"),
  },
  {
    path: "/searcha",
    component: () => import("../views/Search/searcha.vue"),
    children: [
      {
        path: "/searcha",
        redirect: "/searcha/all",
      },
      {
        path: "/searcha/all",
        component: () => import("../components/Search/Tabview/All.vue"),
      },
      {
        path: "/searcha/essay",
        component: () => import("../components/Search/Tabview/Essay.vue"),
      },
      {
        path: "/searcha/discus",
        component: () => import("../components/Search/Tabview/Discus.vue"),
      },
      {
        path: "/searcha/prod",
        component: () => import("../components/Search/Tabview/Prod.vue"),
      },
      {
        path: "/searcha/elem",
        component: () => import("../components/Search/Tabview/Elem.vue"),
      },
    ],
  },
  {
    path: "/:pathMatch(.*)*",
    component: () => import("../views/NotFound404.vue"),
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
// router.beforeEach((to, from, next) => {
//   if (to.meta.requireLogin) {
//     if (localStorage.getItem("token")) {
//       next();
//     } else {
//       next("/login");
//     }
//   } else {
//     next();
//   }
// });

export default router;
